<template>
  <BaseDialog  :loading="loading" destroy-on-close @confirm="confirm" @close="close" confirmText="确定" v-model="isShow" title="选择字表">
      <div class="flex flex-col">
        <div class="flex">
          <el-form @submit="listTableInfoHandle" :inline="true" :model="queryForm" >
            <el-form-item label="表名称">
              <el-input v-model="queryForm.tableName" placeholder="请输入表名称" />
            </el-form-item>
          </el-form>
          <el-button type="primary" >查询</el-button>
        </div>
        <div>
          <el-table height="300px" ref="tableRef" v-loading="loading" :data="data">
            <el-table-column type="selection" width="55" />
            <el-table-column type="index" label="序号" width="60" align="center" header-align="center"/>
            <el-table-column prop="tableName" label="表名称"/>
            <el-table-column prop="className" label="类名称" align="center" header-align="center" width="180">
            </el-table-column>
            <el-table-column prop="descName" label="描述名称" align="center" header-align="center" width="180">
            </el-table-column>
          </el-table>
        </div>
      </div>

  </BaseDialog>
</template>

<script setup lang="ts">
import {reactive, ref} from "vue";
import {listTableInfo} from "/@/api/generator/TableInfoApi";
import {TableInfoModel, TableInfoQueryModel} from "/@/api/generator/model/TableInfoModel";
import {ElMessage} from "element-plus";
const isShow = ref(false)
const loading = ref(false)
const tableRef = ref()
const queryForm = reactive<TableInfoQueryModel>({
  tableName: ''
})
const data = ref<TableInfoModel[]>([])
const emit = defineEmits(["load"])
const init = async() => {
  isShow.value = true
  await listTableInfoHandle()
}
const listTableInfoHandle = async () => {
  loading.value = true
  let res = await listTableInfo(queryForm,()=>{
    loading.value = false
  })
  data.value = res
}
const confirm = async () => {
  let rows = tableRef.value.getSelectionRows()
  if(rows.length === 0){
    ElMessage.warning("请选择一条信息");
    return;
  }
  emit("load",rows)
  close()
}
const close = () => {

  isShow.value = false
}
defineExpose({init})
</script>

<style scoped>

</style>